package com.modifiertech.lineage;

import com.modifiertech.lineage.api.LineageAPI;
import com.modifiertech.lineage.api.LineageModAccess;
import com.modifiertech.lineage.base.CommonProxy;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import org.apache.logging.log4j.Logger;

@Mod(modid = BaseConst.MODID, name = BaseConst.MODNAME, version = BaseConst.MODVERSION,guiFactory = BaseConst.GUI_FACTORY)
public class Lineage
{
    //代理模式的理解非常重要！！！
    @SidedProxy(serverSide = BaseConst.PROXY_COMMON,clientSide = BaseConst.PROXY_CLIENT)
    public static CommonProxy proxy;

    public static Logger logger;

    public Lineage() {
        LineageAPI.setInstance(new LineageAPI(new LineageModAccess()));
    }




    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        logger = event.getModLog();
        proxy.preInit(event);
    }

    @EventHandler
    public void init(FMLInitializationEvent event)
    {
        proxy.init(event);
    }

    @EventHandler
     public void postInit(FMLPostInitializationEvent event){
        proxy.postInit(event);
     }

     @EventHandler
    public void serverStarting(FMLServerStartingEvent event) {
        proxy.serverStarting(event);
    }


    public static boolean isSinglePlayer() {
        MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
        // 如果服务器实例存在且是单人模式，返回 true
        if (server != null && server.isSinglePlayer()) {
            return true;
        }
        return false;
    }

}
